<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Hash;
class ResjsController extends Controller
{
    //前台注册js 邮箱
  public function getAjax(){
  	// var_dump($_GET);
  // 	// dd($request->all());
        $sta = DB::table('member')->where('email',$_GET['cda'])->get();
        // dd(json_encode($sta));
        if($sta){
        	return 'yes';
        }else{
        	return 'no';
        }
   
  }

      //前台注册js 手机
  public function getPhone(){
  	// var_dump($_GET);
  // 	// dd($request->all());
        $sta = DB::table('member')->where('phone',$_GET['cda'])->get();
        // dd(json_encode($sta));
        if($sta){
        	return 'yes';
        }else{
        	return 'no';
        }
   
  }
//验证码js
  public function getCode($set){

  	if(session('milkcaptcha')==$set){
  		return 'yes';
  	}else{
  		return 'no';
  	}
  }
//登录验证
  public function getLogin(){
  	return view('home.login');
  }
 
  public function postLogins(Request $request){
     //查询用户是否存在
    $user = DB::table('member')->where('email','=',$request->input('email'))->first();
    // dd($user);
    if(count($user)){//用户名存在
        // dd(Hash::check($request->input['pass'],$user['pass']));
        if(Hash::check($request->input('pass'),$user['pass'])){
            //将用户信息写入session保存 目的是为了中间件检测通过
            session(['adminuser'=>$user]);
            // dd(session(['adminuser'=>$user]));
            return redirect('index.php')->with('success','登录成功');
            }else{
              return   back()->with('error','密码不正确');
            }
        }else{
            return back()->with('error','用户名不存在');
        }
  }
}
